<?php

/**
 * This is the model class for table "tb_ref".
 *
 * The followings are the available columns in table 'tb_ref':
 * @property integer $ref_id
 * @property integer $brand_id
 * @property string $ref_name
 * @property string $ref_image_path
 * @property string $ref_detail
 * @property string $created_by
 * @property string $created_date
 * @property string $updated_by
 * @property string $updated_date
 */
class Ref extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return Ref the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tb_ref';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('brand_id, ref_name, ref_image_path', 'required'),
            array('brand_id', 'numerical', 'integerOnly' => true),
            array('ref_name', 'length', 'max' => 100),
            array('ref_image_path', 'length', 'max' => 255),
            array('created_by, updated_by', 'length', 'max' => 20),
            array('ref_detail, created_date, updated_date', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('ref_id, brand_id, ref_name, ref_image_path, ref_detail, created_by, created_date, updated_by, updated_date', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'ref_id' => 'Ref',
            'brand_id' => 'Brand',
            'ref_name' => 'Ref Name',
            'ref_image_path' => 'Ref Image Path',
            'ref_detail' => 'Ref Detail',
            'created_by' => 'Created By',
            'created_date' => 'Created Date',
            'updated_by' => 'Updated By',
            'updated_date' => 'Updated Date',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('ref_id', $this->ref_id);
        $criteria->compare('brand_id', $this->brand_id);
        $criteria->compare('ref_name', $this->ref_name, true);
        $criteria->compare('ref_image_path', $this->ref_image_path, true);
        $criteria->compare('ref_detail', $this->ref_detail, true);
        $criteria->compare('created_by', $this->created_by, true);
        $criteria->compare('created_date', $this->created_date, true);
        $criteria->compare('updated_by', $this->updated_by, true);
        $criteria->compare('updated_date', $this->updated_date, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}